Conditions | 2 |
Paths | 4 |
Total Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** global: GLSR, site_reviews, site_reviews_pointers, wp, x */ |
||
3 | x( function() |
||
4 | { |
||
5 | x('.glsr-button-reset').on( 'click', function() { |
||
6 | return confirm( site_reviews.are_you_sure ); |
||
7 | }); |
||
8 | |||
9 | var GLSR_textarea = x( '#contentdiv > textarea' ); |
||
10 | if( GLSR_textarea.length ) { |
||
11 | GLSR.textareaResize( GLSR_textarea ); |
||
12 | x( document ).on( 'wp-window-resized.editor-expand', function() { |
||
13 | GLSR.textareaResize( GLSR_textarea ); |
||
14 | }); |
||
15 | } |
||
16 | |||
17 | x( 'form' ).on( 'click', '#clear-log', GLSR.onClearLog ); |
||
18 | |||
19 | x.each( site_reviews_pointers.pointers, function( i, pointer ) { |
||
20 | GLSR.pointers( pointer ); |
||
21 | }); |
||
22 | |||
23 | GLSR.colorControls(); |
||
24 | |||
25 | new GLSR.pinned(); |
||
26 | new GLSR.tabs(); |
||
27 | new GLSR.forms( 'form.glsr-form' ); |
||
28 | new GLSR.status( 'a.glsr-change-status' ); |
||
29 | new GLSR.search( '#glsr-search-posts', { |
||
30 | action: 'search-posts', |
||
31 | onInit: function() { |
||
32 | this.el.on( 'click', '.glsr-remove-button', this.onUnassign.bind( this )); |
||
33 | }, |
||
34 | onResultClick: function( ev ) { |
||
35 | var result = x( ev.target ); |
||
36 | var template = wp.template( 'glsr-assigned-post' ); |
||
37 | var entry = { |
||
38 | url: result.data( 'url' ), |
||
39 | title: result.text(), |
||
40 | }; |
||
41 | if( template ) { |
||
42 | this.el.find( 'input#assigned_to' ).val( result.data( 'id' )); |
||
43 | this.el.find( '.description' ).html( template( entry )); |
||
44 | this.el.on( 'click', '.glsr-remove-button', this.onUnassign.bind( this )); |
||
45 | this.reset(); |
||
46 | } |
||
47 | }, |
||
48 | }); |
||
49 | new GLSR.search( '#glsr-search-translations', { |
||
50 | action: 'search-translations', |
||
51 | onInit: function() { |
||
52 | this.makeSortable(); |
||
53 | }, |
||
54 | onResultClick: function( ev ) { |
||
55 | var result = x( ev.target ); |
||
56 | var entry = result.data( 'entry' ); |
||
57 | var template = wp.template( 'glsr-string-' + ( entry.p1 ? 'plural' : 'single' )); |
||
58 | entry.index = this.options.entriesEl.children().length; |
||
59 | entry.prefix = this.options.resultsEl.data( 'prefix' ); |
||
60 | if( template ) { |
||
61 | this.options.entriesEl.append( template( entry )); |
||
62 | this.options.exclude.push({ id: entry.id }); |
||
63 | this.options.results = this.options.results.filter( function( i, el ) { |
||
64 | return el !== result.get(0); |
||
65 | }); |
||
66 | } |
||
67 | this.setVisibility(); |
||
68 | }, |
||
69 | }); |
||
70 | |||
71 | GLSR.modules = { |
||
72 | shortcode: new GLSR.shortcode( '.glsr-mce' ), |
||
73 | }; |
||
74 | }); |
||
75 |